package com.china08.yxyapi.entity.mg.office;

import java.util.List;
import java.util.Optional;

import javax.persistence.Id;

import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import com.china08.yxyapi.entity.mg.MongoBaseEntityNoId;
import com.china08.yxyapi.util.DateToolUtils;

@Document(collection = "yxy.oa.notice.outter")
public class YxyNoticeOutter extends MongoBaseEntityNoId {

    /**
     * 
     */
    private static final long serialVersionUID = 2479735700797468284L;

    @Id
    private String id;

    /** The user id. 发件人id */
    @Indexed
    @Field(value = "user_id")
    private String userId;

    /** The user name. 发件人名称 */
    @Field(value = "user_nick")
    private String userNick;
    /**
     * 用户头像
     */
    @Field(value = "avatar")
    private String avatar;

    /** 发件教育局:ID */
    @Field(value = "edb_id")
    private String edbId;

    /** 发件教育局名称 */
    @Field(value = "edb_name")
    private String edbName;

    /** The title. 标题 */
    @Field(value = "title")
    private String title;

    /** The content. 内容 */
    @Field(value = "content")
    private String content;

    private String createDate;

    /**
     * 教育局通知，发送针对学校，学校名称
     */
    @Field(value = "receive_school")
    private List<YxyNotifictionSchool> receiveSchool;

    /**
     * 图片附件,可以放置多张图片
     */
    @Field(value = "image")
    private List<String> image;

    /** The adjunct. 附件的文件路径,附件原始文件名称。 */
    @Field(value = "attachment_name")
    private String attachmentName;

    @Field(value = "attachment_path")
    private String attachmentPath;

    /** The status. 状态 0 发件人已发出 -1：发件人已删除 */
    @Field(value = "delete_status")
    private int deleteStatus = 0;

    public String getCreateDate() {
        return createDate = DateToolUtils.format(getCreatedDate(), "yyyy-MM-dd");
    }

    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    public class YxyNotifictionSchool {
        // 接受学校id
        public String schoolId;
        // 接受学校名
        public String schoolName;
        // 是否已读 0 未读 1 已读
        public int isRead = 0;
        // 0：存在 -1 已删除
        public int isDelete = 0;

        public String getSchoolId() {
            return schoolId;
        }

        public void setSchoolId(String schoolId) {
            this.schoolId = schoolId;
        }

        public String getSchoolName() {
            return schoolName;
        }

        public void setSchoolName(String schoolName) {
            this.schoolName = schoolName;
        }

        public int getIsRead() {
            return isRead;
        }

        public void setIsRead(int isRead) {
            this.isRead = isRead;
        }

        public int getIsDelete() {
            return isDelete;
        }

        public void setIsDelete(int isDelete) {
            this.isDelete = isDelete;
        }

    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserNick() {
        return userNick;
    }

    public void setUserNick(String userNick) {
        this.userNick = userNick;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getEdbId() {
        return edbId;
    }

    public void setEdbId(String edbId) {
        this.edbId = edbId;
    }

    public String getEdbName() {
        return edbName;
    }

    public void setEdbName(String edbName) {
        this.edbName = edbName;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public List<YxyNotifictionSchool> getReceiveSchool() {
        return receiveSchool;
    }

    public void setReceiveSchool(List<YxyNotifictionSchool> receiveSchool) {
        this.receiveSchool = receiveSchool;
    }

    public List<String> getImage() {
        return image;
    }

    public void setImage(List<String> image) {
        this.image = image;
    }

    public String getAttachmentName() {
        return attachmentName;
    }

    public void setAttachmentName(String attachmentName) {
        this.attachmentName = attachmentName;
    }

    public String getAttachmentPath() {
        return attachmentPath;
    }

    public void setAttachmentPath(String attachmentPath) {
        this.attachmentPath = attachmentPath;
    }

    public int getDeleteStatus() {
        return deleteStatus;
    }

    public void setDeleteStatus(int deleteStatus) {
        this.deleteStatus = deleteStatus;
    }

    // 外部通信 获取所有的接受用户名称
    public Optional<String> getAllReceiveSchoolName(String splitStr) {
        return receiveSchool.stream().map(s -> s.schoolName).reduce((s1, s2) -> s1 + splitStr + s2);
    }

    public Optional<YxyNotifictionSchool> getCurrentReceiver(String edbId) {
        return receiveSchool.stream()//
                .filter(x -> {
                    return x.getSchoolId().contains(edbId);
                }).findFirst();
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

}
